package cn.ichiva.service;

import org.springframework.data.redis.core.ValueOperations;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class ValueService {
    private final ValueOperations<String, String> value;

    public ValueService(ValueOperations<String, String> value) {
        this.value = value;
    }

    public void set(String key, String value) {
        this.value.set(key, value);
    }

    public void setByExpire(String key, String value, long timeout) {
        this.value.set(key, value, timeout, TimeUnit.MILLISECONDS);
    }

    public Boolean setIfAbsent(String key, String value) {
        return this.value.setIfAbsent(key, value);
    }

    public Boolean setIfAbsentByExpire(String key, String value, long timeout) {
        return this.value.setIfAbsent(key, value,timeout,TimeUnit.MILLISECONDS);
    }

    public Boolean setIfPresent(String key, String value) {
        return this.value.setIfPresent(key,value);
    }

    public Boolean setIfPresentByExpire(String key, String value, long timeout) {
        return this.value.setIfPresent(key, value,timeout,TimeUnit.MILLISECONDS);
    }

    public void multiSet(Map<? extends String, ? extends String> map) {
        this.value.multiSet(map);
    }

    public Boolean multiSetIfAbsent(Map<? extends String, ? extends String> map) {
        return this.value.multiSetIfAbsent(map);
    }

    public String get(String key) {
        return this.value.get(key);
    }

    public String getAndSet(String key, String value) {
        return this.value.getAndSet(key, value);
    }

    public List<String> multiGet(Collection<String> keys) {
        return this.value.multiGet(keys);
    }

    public Long increment(String key) {
        return this.value.increment(key);
    }

    public Long incrementLong(String key, long delta) {
        return this.value.increment(key, delta);
    }

    public Double incrementDouble(String key, double delta) {
        return this.value.increment(key, delta);
    }

    public Long decrement(String key) {
        return this.value.decrement(key);
    }

    public Long decrementLong(String key, long delta) {
        return this.value.decrement(key, delta);
    }

    public Integer append(String key, String value) {
        return this.value.append(key, value);
    }

    public String getIn(String key, long start, long end) {
        return this.value.get(key, start, end);
    }

    public Long size(String key) {
        return this.value.size(key);
    }
}
